/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.dto;

import com.niedziela12.pai.ejb.entities.Reservation;
import com.niedziela12.pai.ejb.entities.Role;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import com.niedziela12.pai.ejb.entities.User;
import com.niedziela12.pai.ejb.entities.UserRoles;
import java.util.ArrayList;

/**
 *
 * @author Kamil
 */
@XmlType(propOrder = {
    "id"
})
@XmlAccessorType(XmlAccessType.FIELD)
public class UserDTO implements Serializable {
    @XmlTransient
    private static final long serialVersionUID = 1L;
    @XmlElement(name = "USER_ID")
    private Long id;
//    @XmlTransient
//    private List<ReservationDTO> reservations;
    @XmlTransient
    private String firstName;
    @XmlTransient
    private String lastName;
    @XmlTransient
    private String login;
    @XmlTransient
    private String password;
//    private List<UserRolesDTO> roles;
    
    public UserDTO(){   
    }

    public UserDTO(User user) {
        if (user != null) {
            this.id = user.getId();
//            this.reservations = new ArrayList<ReservationDTO>();
//            for (Reservation r : user.getReservations()) {
//                reservations.add(new ReservationDTO(r));
//            }
            this.firstName = user.getFirstName();
            this.lastName = user.getLastName();
            this.login = user.getLogin();
            this.password = user.getPassword();
//            this.roles = new ArrayList<UserRolesDTO>();
//            for (UserRoles r : user.getUserRolesList()) {
//                roles.add(new UserRolesDTO(r));
//            }
        }
    }
    
    public User toUser(){
        User usr = new User();
        usr.setFirstName(firstName);
        usr.setId(id);
        usr.setLastName(lastName);
        usr.setLogin(login);
        usr.setPassword(password);
        List<Reservation> res = new ArrayList<Reservation>();
//        for(ReservationDTO r : reservations)res.add(r.toReservation());
        usr.setReservations(res);
        List<UserRoles> rls = new ArrayList<UserRoles>();
//        for(UserRolesDTO r : roles)rls.add(r.toUserRoles());
        usr.setUserRolesList(rls);
        return usr;
    }
    
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

//    public List<ReservationDTO> getReservations() {
//        return reservations;
//    }
//
//    public void setReservations(List<ReservationDTO> reservations) {
//        this.reservations = reservations;
//    }

//    public List<UserRolesDTO> getRoles() {
//        return roles;
//    }
//
//    public void setRoles(List<UserRolesDTO> roles) {
//        this.roles = roles;
//    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserDTO)) {
            return false;
        }
        UserDTO other = (UserDTO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return firstName + " " + lastName + " / login:" + login ;
    }

}
